package com.mobile.view.config;

import com.mobile.view.controller.ViewController;
import com.mobile.view.util.GetIpAddress;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;

import java.io.IOException;

/**
 * @author LaZY(李志一)
 * @create 2019-06-08 11:30
 */
@Configuration
public class IndexConfig {

    @EventListener({ApplicationReadyEvent.class})
    public void applicationReadyEvent() {
        System.out.println("应用已经准备就绪 ... 启动浏览器");
        ViewController.host = "http://" + GetIpAddress.getInnerIp() + "/";
        Runtime runtime = Runtime.getRuntime();
        try {
            //https://www.iteye.com/blog/nicekevin-2274947
            runtime.exec("rundll32 url.dll,FileProtocolHandler " + ViewController.host);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
